export default function useWatchRouteLinkActiveStyle() {
    const setStyle = (style: object) => {
        
        if (!style || JSON.stringify(style) === "{}") return
        const routeLinkEl: HTMLElement = document.querySelector(".h-router-active");

        if (!routeLinkEl) return
        // for遍历style对象，设置css变量
        for (const key in style) {
            if (Object.prototype.hasOwnProperty.call(style, key)) {
                routeLinkEl.style.setProperty(key, style[key])
            }
        }
    }
    const resetStyle = (style: object, classname: string) => {
        if (!style || JSON.stringify(style) === "{}") return
        const routeLinkEls: NodeListOf<HTMLElement> = document.querySelectorAll("." + classname)

        if (!routeLinkEls || !routeLinkEls.length) return
        // 移除style中的样式，为每一个dom
        for (const key in style) {
            if (Object.prototype.hasOwnProperty.call(style, key)) {
                routeLinkEls.forEach(el => el.style.removeProperty(key))
            }
        }
    }

    return {
        setStyle,
        resetStyle
    }
}
